//
//  MyMovieViewController.m
//  豆瓣(阿黄)
//
//  Created by 黄俊杰 on 15/11/4.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MyMovieViewController.h"
#import "DataBase.h"
#import "MovieDetail.h"
#import "MovieDetailViewController.h"

@interface MyMovieViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)NSMutableArray *array;

@end

@implementation MyMovieViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"我的电影";
    
    self.myMovieTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    
    self.myMovieTableView.delegate = self;
    self.myMovieTableView.dataSource = self;
    [self.view addSubview:self.myMovieTableView];
    [self.myMovieTableView release];
    
    [self.myMovieTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"myMovieCell"];
    
    self.array = [NSMutableArray array];
    self.array = [[DataBase shareDataBase] selectMovieDetail:1];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellId = @"myMovieCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    
    MovieDetail *movieD = [self.array objectAtIndex:indexPath.row];
    cell.textLabel.text = movieD.title;
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    MovieDetailViewController *movieDVC = [[MovieDetailViewController alloc] init];
    MovieDetail *movieD = [self.array objectAtIndex:indexPath.row];
    movieDVC.movieId = movieD.movieId;
    [self.navigationController pushViewController:movieDVC animated:1];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
